﻿#ifndef _SQLSTANDARDIZATION_H_
#define _SQLSTANDARDIZATION_H_


#include "udatabase/dll_cfg.h"
#include "kernel/Referenced.h"


namespace FD{
	namespace Utility{
		namespace DB{
			    class CSqlQuery;
				///<summary>
				///由于不同数据库上sql语句中关键字有所不同，
				///通过此类创建统一的方法
				///</summary>
				class FD_DB_Export CSqlstandardization : public FD::Kernel::CReferenced
				{					
				public:
					///<summary>
					///构造函数
					/// </summary>
					/// <param name="driverType">驱动名</param>
					///<returns></returns>
					CSqlstandardization(const FD::Kernel::FdUnicodeString & driverType);
				public:

					///<summary>
					///获取当前时间
					/// </summary>
					/// <param name=""></param>
					///<returns>当前时间</returns>
					const CHAR* sqlcurrentTime() const;
					///<summary>
					///不同数据库上自增长字段关键字
					/// </summary>
					/// <param name=""></param>
					///<returns>自增长字段关键字</returns>
					const CHAR* sqlautoincrement() const;
					///<summary>
					///达梦数据库上自增长字段关键字
					/// </summary>
					/// <param name=""></param>
					///<returns>自增长字段关键字</returns>
					const CHAR* sqlDMautoincrement() const;
					///<summary>
					///不同数据库上字符类型
					/// </summary>
					/// <param name=""></param>
					///<returns>字符类型</returns>
					const CHAR* sqlcharType() const;
					/*const CHAR* sqlOraclesequence() const;//oracle中为了实现自增长功能创建sequence*/
					///<summary>
					///不同数据库上二进制类型（区分image和blob）
					/// </summary>
					/// <param name=""></param>
					///<returns>二进制类型</returns>
					const CHAR* sqlbinaryType() const;
					///<summary>
					///选出sqlserver数据库中查询结果的前row行
					/// </summary>
					/// <param name="str"></param>
					/// <param name="row">行数</param>
					///<returns></returns>
					void SqlserverSelectTop( String &str,INT32 row);
					///<summary>
					///选出查询结果的前row行（除sqlserver，dm外）
					/// </summary>
					/// <param name="str"></param>
					/// <param name="row">行数</param>
					///<returns></returns>
					void sqlSelectTop( String &str,INT32 row);
					///<summary>
					///时间类型
					/// </summary>
					/// <param name=""></param>
					///<returns>时间类型</returns>
					const CHAR* sqlDateType() const;
					///<summary>
					///自增长字段
					/// </summary>
					/// <param name="fieldname">字段名</param>
					///<returns>字段名</returns>
					String sqlautoincrementField(const CHAR* fieldname) const;
					///<summary>
					///插入语句中自增长字段的值
					/// </summary>
					/// <param name="fieldname">字段名</param>
					///<returns>字段值</returns>
					String sqlautoincrementFieldValue(const CHAR *tablename) const;
					///<summary>
					///oracle中为了实现自增长功能创建sequence
					/// </summary>
					/// <param name="tablename">表名</param>
					///<returns>序列</returns>
					const CHAR* sqlOraclesequence(const CHAR *tablename) const;
					///<summary>
					///获取最后一条插入记录的主码值
					/// </summary>
					/// <param name="curQuery">查询对象</param>
					/// <param name="tablename">表名</param>
					///<returns>主码值</returns>
					INT32 getLastPrimaryKeyVal(FD::Utility::DB::CSqlQuery& curQuery,const CHAR* tablename);
				private:
					String sqlIntercept(const String& name) const;//对于长度超过30的表名处理
					inline void createOracleSeqName(const CHAR* tablename, String& seqname) const;
				private:
					// SQLITE, SQLSERVER, MYSQL, ORACLE 
					FD::Kernel::FdUnicodeString m_driverType;
					static UINT32 m_index;
				};

			}}} // End of Namespace

#endif //_DATASET_ITERATOR_H_H_
